package com.company.controller;

import com.company.constant.MessageConstant;
import com.company.entity.Result;
import com.company.pojo.Setmeal;
import com.company.service.SetMealService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author fu xiao liu
 * @date 2021-08-11 11:37
 */

@RestController
@RequestMapping("/setmeal")
public class SetMealController {

    @DubboReference
    private SetMealService setmealService;



    @RequestMapping("/getAllSetmeal")
    public Result getAllSetmeal(){
        try {
            List<Setmeal> list = setmealService.findAll();
            return new Result(true, MessageConstant.GET_SETMEAL_LIST_SUCCESS,list);
        }catch (Exception e) {
            return new Result(false, MessageConstant.GET_SETMEAL_LIST_FAIL);
        }
    }


    @RequestMapping("/findById")
    public Result findById(Integer id){
        Setmeal setmeal=null;
        try {
            setmeal =  setmealService.findById(id);
        } catch (Exception e) {
            //删除失败
            e.printStackTrace();
            //服务调用失败    Result是对于新增操作结果的封装
            return new Result(false, MessageConstant.QUERY_SETMEAL_FAIL);
        }
        return  new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS,setmeal);
    }
}
